﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

using SBPweb.RIA.Shared.Contracts.Components;

using SBPweb.PROvibe.Server.Library.Services;

using SBPweb.PROvibe.Shared.Library.Components;

namespace SBPweb.PROvibe.Server.Core.Services
{

    public class ServiceManager : InitializableBase, IServiceManager
    {

        #region Fields

        private ObservableCollection<IService> services = new ObservableCollection<IService>();

        #endregion

        #region Constructor logic

        internal ServiceManager()
        {
            Services = new ReadOnlyObservableCollection<IService>(services);
        }

        #endregion

        #region Properties

        public ReadOnlyObservableCollection<IService> Services
        {
            get;
            private set;
        }

        #endregion

        #region Methods

        protected override void OnInitialize()
        {
            foreach (IService service in Services)
            {
                service.Initialize();
            }
        }

        protected override void OnTerminate()
        {
        }

        public void RegisterService(IService service)
        {
            services.Add(service);
        }

        public void UnregisterService(IService service)
        {
            services.Remove(service);
        }

        #endregion

    }

}